package com.wn.consumer06;

import com.rabbitmq.client.Channel;
import com.wn.bean.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author yellow Docter
 * @date 2023 -02-28
 * @desc
 */
@Component
@Slf4j
public class DeadConsumer {

    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(name="dead-queue"),
                    exchange = @Exchange(
                            name = "exchange-dlx",
                            type = ExchangeTypes.DIRECT
                    ),
                    key = "lisi"
            )
    )
    // @Payload User user (把mq中的json 字符串    转成了  {"name":"jack","age":30} java对象 User )
    public void handlerMsg(@Payload User user, Channel channel, Message message) throws IOException {
        //拒绝消息
        log.info("死信消费者消息的死信队列中的消息:=====>{}",user);

    }
//    public void handlerMsg(String msg, Channel channel, Message message) throws IOException {
//        //拒绝消息
//        log.info("死信消费者消息的死信队列中的消息:=====>{}",msg);
//
//    }
}
